package me.yushuai.wukong.base.service;

import me.yushuai.wukong.base.api.dto.ConfigVariableBizId;
import me.yushuai.wukong.base.entity.ConfigVariable;
import me.yushuai.wukong.common.exceptin.NotExistException;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;

/**
 * @author zhoushuai@189.cn
 * @since 2023-05-24
 */
public interface ConfigVariableService {

    /**
     * 通过ID查询配置项的详细信息
     *
     * @param groupId 配置项编号
     * @param confId  配置项编号
     * @return 返回配置项的详细信息
     * @throws NotExistException 当配置项不存在时抛出异常
     */
    ConfigVariable findConfigVariableById(Long groupId, Long confId) throws NotExistException;

    /**
     * get value of Conf and convert to {@link Boolean}, if the conf not exist or not support convert return the default value
     */
    Boolean boolValue(String configBizId, String configVariableBizId, Boolean defaultValue);

    /**
     * get value of Conf and convert to {@link Boolean}
     */
    Boolean boolValue(String configBizId, String configVariableBizId);

    /**
     * get value of Conf and convert to {@link Boolean}, if the conf not exist or not support convert return the default value
     */
    Boolean boolValue(ConfigVariableBizId conf, Boolean defaultValue);

    /**
     * get value of Conf and convert to {@link Boolean}
     */
    Boolean boolValue(ConfigVariableBizId conf);

    /**
     * get value of Conf and convert it to {@link Integer} and return it.
     */
    Integer intValue(String configBizId, String configVariableBizId);

    /**
     * get value of Conf and convert to {@link Integer}, if the conf not exist or not support convert return the defaultValue
     */
    Integer intValue(String configBizId, String configVariableBizId, int defaultValue);

    /**
     * get value of Conf and convert it to {@link Integer} and return it.
     */
    Integer intValue(ConfigVariableBizId conf);

    /**
     * get value of Conf and convert to {@link Integer}, if the conf not exist or not support convert return the defaultValue
     */
    Integer intValue(ConfigVariableBizId conf, int defaultValue);

    /**
     * get value of Conf and convert it to {@link Long} and return
     */
    Long longValue(String configBizId, String configVariableBizId);

    /**
     * get value of Conf and convert it to {@link Long}, if the Conf not exists or not support convert return the defaultValue.
     */
    Long longValue(String configBizId, String configVariableBizId, long defaultValue);

    /**
     * get value of Conf and convert it to {@link Long}, if the Conf not exists or not support convert return the defaultValue.
     */
    Long longValue(ConfigVariableBizId conf, long defaultValue);

    /**
     * get value of Conf and convert it to {@link Long} and return
     */
    Long longValue(ConfigVariableBizId conf);


    /**
     * get value of Conf and convert it to {@link String} and return.
     */
    String strValue(String configBizId, String configVariableBizId);

    /**
     * get value of Conf and convert it to {@link String}, if the conf not exists return the defaultValue.
     */
    String strValue(String configBizId, String configVariableBizId, String defaultValue);

    /**
     * get value of Conf and convert it to {@link String} and return.
     */
    String strValue(ConfigVariableBizId conf);

    /**
     * get value of Conf and convert it to {@link String}, if the conf not exists return the defaultValue.
     */
    String strValue(ConfigVariableBizId conf, String defaultValue);

    /**
     * get value of Conf and convert it to {@link Date} and return it.
     */
    Date dateValue(String configBizId, String configVariableBizId);

    /**
     * get value of Conf and convert it to {@link Date}, if the Conf not exists or not support convert return the defaultValue.
     */
    Date dateValue(String configBizId, String configVariableBizId, Date defaultValue);

    /**
     * get value of Conf and convert it to {@link Date} and return it.
     */
    Date dateValue(ConfigVariableBizId conf);

    /**
     * get value of Conf and convert it to {@link Date}, if the Conf not exists or not support convert return the defaultValue.
     */
    Date dateValue(ConfigVariableBizId conf, Date defaultValue);

    /**
     * get value of Conf and convert it to {@link Date} and return it.
     */
    LocalDate localDateValue(String configBizId, String configVariableBizId);

    /**
     * get value of Conf and convert it to {@link LocalDate}, if the Conf not exists or not support convert return the defaultValue.
     */
    LocalDate localDateValue(String configBizId, String configVariableBizId, LocalDate defaultValue);

    /**
     * get value of Conf and convert it to {@link Date} and return it.
     */
    LocalDate localDateValue(ConfigVariableBizId conf);

    /**
     * get value of Conf and convert it to {@link LocalDate}, if the Conf not exists or not support convert return the defaultValue.
     */
    LocalDate localDateValue(ConfigVariableBizId conf, LocalDate defaultValue);

    /**
     * get value of Conf and convert it to {@link java.time.LocalDateTime} return it.
     */
    LocalDateTime localDateTimeValue(String configBizId, String configVariableBizId);

    /**
     * get value of Conf and convert it to {@link java.time.LocalDateTime}, if the Conf not exists or not support convert return the defaultValue.
     */
    LocalDateTime localDateTimeValue(String configBizId, String configVariableBizId, LocalDateTime defaultValue);

    /**
     * get value of Conf and convert it to {@link java.time.LocalDateTime} return it.
     */
    LocalDateTime localDateTimeValue(ConfigVariableBizId conf);

    /**
     * get value of Conf and convert it to {@link java.time.LocalDateTime}, if the Conf not exists or not support convert return the defaultValue.
     */
    LocalDateTime localDateTimeValue(ConfigVariableBizId conf, LocalDateTime defaultValue);

    /**
     * get value of Conf if the conf not exists than throw exception.
     *
     * @param configBizId         the groupBizId of ConfGroup
     * @param configVariableBizId this confBizId of Conf
     * @param clazz               the class is want to class
     * @param <T>                 the type is want to return
     * @return return value types' is <T>
     */
    <T> T getValue(String configBizId, String configVariableBizId, Class<T> clazz);

    /**
     * get value of Conf if the conf not exists or value convertor fail return defaultValue.
     *
     * @param configBizId         the groupBizId is bizId of ConfGroup
     * @param configVariableBizId the confBizId is bizId of Conf
     * @param defaultValue        when the value is null or convertor fail return default value.
     * @param targetType          the class is want to class
     * @param <T>                 the type is want to return
     * @return return value type's is T
     */
    <T> T getValue(String configBizId, String configVariableBizId, T defaultValue, Class<T> targetType);

    /**
     * 使用配置配置的业务id查询配置的值
     *
     * @param conf         配置业务Id
     * @param defaultValue 如果配置不存在或未设置值返回默认值
     * @param targetType   配置的数量类型
     * @param <T>          泛型
     * @return 返回通过数量类型转换器转换后的值
     */
    <T> T getValue(ConfigVariableBizId conf, T defaultValue, Class<T> targetType);

    <T> T getValue(ConfigVariableBizId conf, Class<T> targetType);

    /**
     * 检查配置的值与期望的值是否相同
     *
     * @param conf        配置ID
     * @param expectValue 期望值
     * @param <T>         泛型
     * @return 返回true表示与期望值相同否则表示与期望值不同。
     */
    <T> boolean compareValue(ConfigVariableBizId conf, T expectValue);
}
